package pressepapier;
import java.awt.datatransfer.*;
import java.awt.*;
import java.io.*;

import Debog.Debog;

import editeurimpl.PressePapier;



public class PressePapierSystem extends Debog implements PressePapier
{

        private Clipboard clip;
        public PressePapierSystem(){
                clip=Toolkit.getDefaultToolkit().getSystemClipboard();
        }

        public void setcontenu( String t )
        {
        debog("transfer:"+t);
                try {   StringSelection ss = new StringSelection(t);
                clip.setContents(ss,null);
        } catch (IllegalStateException e){
                debog("echec transfer:"+t);
                }
 
        }
        public String getcontenu()
        { 
                
                try {
                        Transferable t = clip.getContents(null);
                        if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                                String text = (String)t.getTransferData(DataFlavor.stringFlavor);
                                return text;
                                }
                }
        catch (NullPointerException e){}
        catch (IllegalStateException e){}
        catch (UnsupportedFlavorException e) {}
        catch (IOException e) {}
    return "";
        }

 }